﻿#ifndef BCITARGETINTERFACE_H
#define BCITARGETINTERFACE_H

#include <QImage>
#include <QPainter>
#include <QPixmap>
#include <QSharedPointer>
#include <QBciRender>
#include <QBciOpacityRender>
#include <QBciScreenControllerShell>
#include <QBciShape>

// 用于绘制特定目标的接口类
class QBciTargetInterface {
public:
  typedef QSharedPointer<QWaveGeneratorInterface> WaveGenP;
  enum ShowLabelPosition { North, South, East, West, NonePos };

  // 外部调用paint完成接口的绘制
  void paint(QPainter *painter);

  void setGeometry(const int &x, const int &y, const int &width,
                   const int &height) {
    X = x;
    Y = y;
    Width = width;
    Height = height;
  }
  void setGeometry(const QRect &geometry) {
    X = geometry.x();
    Y = geometry.y();
    Width = geometry.width();
    Height = geometry.height();
  }

//  void installWaveGenerator(WaveGenP w) {
//    assert(w != nullptr);
//    Wave = w;
//  }
//  void setEnableWave(const bool &flag) {
//    if (flag != EnableWave)
//      Wave->reset();
//    EnableWave = flag;
//  }

  void setTargetLabel(const QString &label) { Label = label; }
  QString label() { return Label; }

  void setShowLabel(const QString &label, const ShowLabelPosition &pos) {
    ShowLabel = label;
    ShowLabelPos = pos;
  }
  void setShowLabel(const ShowLabelPosition &pos) {
    ShowLabel = Label;
    ShowLabelPos = pos;
  }

  // 当设置时调用这个函数
  virtual void set(){};
  // 当复位时调用这个函数
  virtual void reset(){};

protected:
  // 需要特别绘制的部分通过重新定义这个函数实现
  // 为了保持能够兼容闪烁频率的功能，请不要在该函数内部
  // 设置painter厚度
  virtual void stylePaint(QPainter *painter) = 0;

private:
  void labelPaint(QPainter *painter);

protected:
  // 位置参数
  int X = 0;
  int Y = 0;
  // 长宽参数
  int Width = 0;
  int Height = 0;
  // 标签
  QString Label;
  // 波形生成器
  WaveGenP Wave = nullptr;
  bool EnableWave = false;
  // Target status
  bool Status = false;

  QString ShowLabel = "";
  ShowLabelPosition ShowLabelPos = NonePos;

public:
  QBciShape *shape = new QBciShape;
  QBciRender *render = new QBciOpacityRender;
//  QBciRender *render = new QBciScreenControllerShell;

public:
  int ID;
};

#endif // BCITARGETINTERFACE_H
